/**
 * 详情对话框
 */
var BasicDriverInfoDlg = {
    data: {
        driverOperateId: "",
        driverOperateName: "",
        driverNumber: "",
        driverName: "",
        idcard: "",
        tel: "",
        candrivenumber: "",
        drivenumber: "",
        practitionersnumber: "",
        drivetype: "",
        canvehicletype: "",
        urgentpeople: "",
        urgentpeopletel: "",
        drivedate: "",
        practitionersdate: "",
        yeardrivedate: "",
        yeardrivedateexpire: "",
        yearpractitionersdate: "",
        yearpractitionersdateexpire: "",
        mail: "",
        driverstate: "",
        notes: "",
        version: "",
        createTime: "",
        updateTime: "",
        createUser: "",
        updateUser: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var upload = layui.upload;
    
    //让当前iframe弹层高度适应
    admin.iframeAuto();

    laydate.render({
        elem: '#jiashizhengfazhengriqi' //驾驶证发证日期
    });

    laydate.render({
        elem: '#jiashizhengnianshenriqi' //驾驶证年审日期
    });

    laydate.render({
        elem: '#jiashizhengqishiriqi' //驾驶证起始日期
    });

    laydate.render({
        elem: '#jiashizhengjiezhiriqi' //驾驶证截止日期
    });

    laydate.render({
        elem: '#congyezhengfazhengriqi' //从业证发证日期
    });

    laydate.render({
        elem: '#congyezhengqishiriqi' //从业证起始日期
    });

    laydate.render({
        elem: '#congyezhengzhongzhiriqi' //从业证终止日期
    });

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/basicDriver/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('basicDriverForm', result.data);
    if(result.data.sijiphotofileid != null && result.data.sijiphotofileid != ""){
        $('#avatarPreview').attr('src', '/system/previewa/' + result.data.sijiphotofileid);
    }
    if(result.data.idcarpohtofileid != null && result.data.idcarpohtofileid != ""){
        $('#avatarPreview2').attr('src', '/system/previewa/' + result.data.idcarpohtofileid);
    }
    if(result.data.jiashizhengphotofileid != null && result.data.jiashizhengphotofileid != ""){
        $('#avatarPreview3').attr('src', '/system/previewa/' + result.data.jiashizhengphotofileid);
    }
    if(result.data.congyezhengphotofileid != null && result.data.congyezhengphotofileid != ""){
        $('#avatarPreview4').attr('src', '/system/previewa/' + result.data.congyezhengphotofileid);
    }

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/basicDriver/editItem", function (data) {
        	if (data.success) {
                Feng.success("Updated successfully!");
            	window.location.href = Feng.ctxPath + '/basicDriver'
		} else {
                Feng.error("Update failed!"+data.message);
		}
        }, function (data) {
            Feng.error("Update failed!" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });
    
    upload.render({
        elem: '#imgHead'
        , url: Feng.ctxPath + '/basicDriver/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview').attr('src', result);
            });
        }
        , done: function (res) {
            $('#sijiphotofileid').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/basicDriver'
    });

});
layui.use(['ax', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var upload = layui.upload;
    
    upload.render({
        elem: '#imgHead2'
        , url: Feng.ctxPath + '/basicDriver/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview2').attr('src', result);
            });
        }
        , done: function (res) {
            $('#idcarpohtofileid').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });
});
layui.use(['ax', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var upload = layui.upload;
    
    upload.render({
        elem: '#imgHead3'
        , url: Feng.ctxPath + '/basicDriver/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview3').attr('src', result);
            });
        }
        , done: function (res) {
            $('#jiashizhengphotofileid').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });
});
layui.use(['ax', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var upload = layui.upload;
    
    upload.render({
        elem: '#imgHead4'
        , url: Feng.ctxPath + '/basicDriver/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview4').attr('src', result);
            });
        }
        , done: function (res) {
            $('#congyezhengphotofileid').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });
});
layui.use(['ax', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var upload = layui.upload;
    
    upload.render({
        elem: '#imgHead5'
        , url: Feng.ctxPath + '/basicDriver/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview5').attr('src', result);
            });
        }
        , done: function (res) {
            $('#mail').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });
});